<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改资金落实')" />
    <th:block th:include="include :: jsonview-css" />
    <th:block th:include="includeProject :: project-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content">
        <div class="col-sm-12">
            <div class="row">
                <div class="col-sm-12">
                    <th:block th:include="includeProject :: projectInfo" />
                </div>
            </div>
            <!--<div class="row">
                <div class="col-sm-12">
                    <th:block th:include="includeProject :: projectConstructorInfo" />
                </div>
            </div>-->
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5 style="font: bold">投资建设资金情况</h5>
                            <div class="ibox-tools">
                                <a class="collapse-link">
                                    <i class="fa fa-chevron-up"></i>
                                </a>
                            </div>
                        </div>
                        <div class="ibox-content" id="ibox-content">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form form-horizontal m-t"  id="form-invest-edit">
                                        <input type="hidden" id="projectId" name="projectId" th:value="${project.projectId}">

                                        <div class="col-md-4">
                                            <div class="info-label control-label is-required">总投资：</div>
                                            <div class="info-value">
                                                <div class="input-group m-b col-md-8"><span class="input-group-addon">&yen;</span>
                                                    <input name="totalInvest" placeholder="请输入" class="form-control" type="text" maxlength="10" th:value="${#numbers.formatDecimal(project.totalInvest,1,2)}">
                                                    <span class="input-group-addon">亿元</span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="info-label control-label">资金需求：</div>
                                            <div class="info-value">
                                                <div class="input-group m-b col-md-8"><span class="input-group-addon">&yen;</span>
                                                    <input name="fundDemand" placeholder="请输入" class="form-control" type="text" maxlength="10" th:value="${#numbers.formatDecimal(project.fundDemand,1,2)}">
                                                    <span class="input-group-addon">亿元</span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="info-label control-label is-required" th:text="${currentYear} + '年计划投资：'"></div>
                                            <div class="info-value">
                                                <div class="input-group m-b col-md-8"><span class="input-group-addon">&yen;</span>
                                                    <input name="planInvest" placeholder="请输入" class="form-control" type="text" maxlength="10" th:value="${#numbers.formatDecimal(project.planInvest,1,2)}">
                                                    <span class="input-group-addon">亿元</span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="hr-line-dashed"></div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="info-label control-label">已累计完成投资</div>
                                            <div class="info-value" th:text="${project.totalInvest != null?#numbers.formatDecimal(project.doneInvest,1,2):'-'} + ' 亿元'"></div>
                                        </div>
                                        <div class="col-md-6"  th:each="investStat : ${investStat}">
                                            <div class="info-label control-label" th:text="${investStat.year} + '累计完成投资'"></div>
                                            <div class="info-value" th:text="${investStat.doneInvest != null?#numbers.formatDecimal(investStat.doneInvest,1,2):'-'} + ' 亿元'"></div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="hr-line-dashed"></div>
                                        </div>
                                        <!--<div class="col-md-6">
                                            <div class="info-label control-label">实际到位资金：</div>
                                            <div class="info-value">
                                                <div class="input-group m-b col-md-5"><span class="input-group-addon">&yen;</span>
                                                    <input name="actualInvest" placeholder="请输入" class="form-control" type="text" maxlength="10" th:value="${#numbers.formatDecimal(project.actualInvest,1,2)}">
                                                    <span class="input-group-addon">亿元</span>
                                                </div>
                                            </div>
                                        </div>
                                        -->
                                        <div class="ibox float-e-margins">
                                            <div class="ibox-title">
                                                <h5 style="font: bold" th:text="${currentYear} + '年投资情况'"></h5>
                                                <div class="ibox-tools">
                                                    <a class="collapse-link" id="_projectInfo_link">
                                                        <i class="fa fa-chevron-up"></i>
                                                    </a>
                                                </div>
                                            </div>
                                            <div class="ibox-content">
                                                <div class="row">
                                                    <div class="col-sm-12">
                                                        <div class="col-md-6">
                                                            <div class="col-md-12" th:each="detail : ${projectInvestDetails}">
                                                                <div class="info-label control-label" th:text="${detail.month} + '月：'"></div>
                                                                <div class="info-value">
                                                                    <div class="input-group m-b col-md-5"><span class="input-group-addon">&yen;</span>
                                                                        <input th:name="'investDetails['+ ${detailStat.index}+ '].doneInvest'" placeholder="请输入" class="form-control" type="text" maxlength="10" th:value="${#numbers.formatDecimal(detail.doneInvest,1,2)}">
                                                                        <span class="input-group-addon">亿元</span>
                                                                        <input th:name="'investDetails['+ ${detailStat.index}+ '].month'" type="hidden" th:value="${detail.month}">
                                                                        <input th:name="'investDetails['+ ${detailStat.index}+ '].year'" type="hidden" th:value="${currentYear}">
                                                                        <input th:name="'investDetails['+ ${detailStat.index}+ '].projectInvestDetailId'" type="hidden" th:value="${detail.projectInvestDetailId}">
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--<div class="row">
                <div class="col-sm-12">
                    <th:block th:include="includeProject :: investHistory" />
                </div>
            </div>-->
            <div class="row">
                <div class="col-sm-12">
                    <th:block th:include="includeProject :: approveLogs" />
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm" onclick="$.operate.successTabCallback({'code':'0'});"><i class="fa fa-reply-all"></i>返 回</button>
            <button type="button" class="btn btn-sm btn-primary" onclick="saveProjectInvest()"><i class="fa fa-remove"></i>保存</button>
            <button type="button" class="btn btn-sm btn-info" onclick="submitProjectInvest()" id="submitBtn" disabled><i class="fa fa-plus"></i>上报</button>
        </div>
    </div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<th:block th:include="includeProject :: project-js" />
<script th:inline="javascript">
    var prefix = ctx + "manage/invest"

    function saveProjectInvest() {
        var validateResult = $("#form-invest-edit").validate({
            rules: {
                totalInvest: {
                    required: true,
                    number: true,
                    gt: 0
                },
                /*doneInvest: {
                    required: true,
                    number: true,
                    gt: 0
                },
                actualInvest: {
                    required: true,
                    number: true,
                    gt: 0
                },*/
                planInvest: {
                    required: true,
                    number: true,
                    gt: 0
                },
                fundDemand: {
                    number: true,
                    min: 0
                },
                'investDetails[0].doneInvest':{
                    number: true,
                    min: 0
                },
                'investDetails[1].doneInvest':{
                    number: true,
                    min: 0
                },
                'investDetails[2].doneInvest':{
                    number: true,
                    min: 0
                },
                'investDetails[3].doneInvest':{
                    number: true,
                    min: 0
                },
                'investDetails[4].doneInvest':{
                    number: true,
                    min: 0
                },
                'investDetails[5].doneInvest':{
                    number: true,
                    min: 0
                },
                'investDetails[6].doneInvest':{
                    number: true,
                    min: 0
                },
                'investDetails[7].doneInvest':{
                    number: true,
                    min: 0
                },
                'investDetails[8].doneInvest':{
                    number: true,
                    min: 0
                },
                'investDetails[9].doneInvest':{
                    number: true,
                    min: 0
                },
                'investDetails[10].doneInvest':{
                    number: true,
                    min: 0
                },
                'investDetails[11].doneInvest':{
                    number: true,
                    min: 0
                }
            }
        }).form();
        if (validateResult) {
            $.operate.save(prefix + "/edit", $('#form-invest-edit').serialize());
            $("#submitBtn").removeAttr("disabled");
        } else {
            $.modal.msgError("请完善内容");
        }
    }

    function submitProjectInvest() {
        var validateResult = $("#form-invest-edit").validate({
            rules: {
                totalInvest: {
                    required: true,
                    number: true,
                    gt: 0
                },
                doneInvest: {
                    required: true,
                    number: true,
                    gt: 0
                },
                actualInvest: {
                    required: true,
                    number: true,
                    gt: 0
                },
                planInvest: {
                    required: true,
                    number: true,
                    gt: 0
                },
                fundDemand: {
                    required: true,
                    number: true,
                    gt: 0
                }
            }
        }).form();
        if (!validateResult) {
            $.modal.msgError("请完善上报内容");
            return;
        }
        $.modal.confirm("确定上报该项目投资建设资金情况吗？", function() {
            var projectId = $('#projectId').val();
            $.operate.saveTab(prefix + "/submit", {'projectId':projectId});
        });
    }

    // 合起项目基础信息
    $('#_projectInfo_link').trigger('click');
</script>
</body>
</html>